home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / stlogin4.lzh / CAT.C next >
Encoding:
C/C++ Source or Header  |  1993-06-11  |  837 b   |  38 lines

  1. /* Simple UNIX like cat on ATARI ST. Kees Lemmens; Juli 1992
  2.  
  3.    Also works with pipes like in "cat file | more"
  4.  
  5.    Any questions or suggestions about this program can be send to:
  6.    lemmens@dv.twi.tudelft.nl
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include "ux_misc.h"
  13.  
  14. #define MAXLEN    1000
  15.  
  16. void main(int argc,char *argv[]) 
  17. {    FILE *in;
  18.     char buffer[MAXLEN];
  19.  
  20.     if (argc >1 )
  21.     {    ux2dos(argv[1]);    /* convert slashes */
  22.         if ((in = fopen(argv[1],"r")) == NULL)
  23.         {    fputs("\nCan't open file\n",stderr);
  24.             exit(1);
  25.         }
  26.     }
  27.     else    in = stdin;
  28.     
  29.     do
  30.     {    *buffer='\0';
  31.         fgets(buffer,MAXLEN-1,in);    /* save space for \n */
  32.         if(strrchr(buffer,'\n') == NULL)
  33.             strcat(buffer+strlen(buffer),"\n\0");
  34.         fputs(buffer,stdout);
  35.     } while(! feof(in));
  36.     if (in != stdin) fclose(in);
  37.     exit(0);
  38. }